package com.zczc.dao.api.impl;

import com.zczc.dao.api.MessageUserDao;
import com.zczc.dao.mapper.MessageUserMapper;
import com.zczc.entity.MessageUser;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;
import tk.mybatis.mapper.entity.Example.Criteria;

/**
 * @Author:Mark
 * @Description:
 * @Date: Created on 16:49 2018-12-12
 * @Modify by:
 */
@Repository
public class MessageUserDaoImpl implements MessageUserDao {

  @Autowired
  private MessageUserMapper messageUserMapper;

  @Override
  public Integer addMessageUser(MessageUser messageUser) {
    return messageUserMapper.insertSelective(messageUser);
  }

  @Override
  public Integer deleteMessageByMessageIdLogic(List<String> messageIds) {
    Example example=new Example(MessageUser.class);
    Criteria criteria = example.createCriteria();
    criteria.andIn("messageId",messageIds);
    MessageUser messageUser=new MessageUser();
    messageUser.setDeleted(true);
    return messageUserMapper.updateByExampleSelective(messageUser,example);
  }

  @Override
  public Integer addMessageSuccess(String messageId) {
    MessageUser messageUser=new MessageUser();
    messageUser.setAdded(true);
    Example example=new Example(MessageUser.class);
    Criteria criteria = example.createCriteria();
    criteria.andEqualTo("messageId",messageId);
    return messageUserMapper.updateByExampleSelective(messageUser,example);
  }

  @Override
  public List<MessageUser> getAllMessageInfoId(String userId) {
    Example example=new Example(MessageUser.class);
    Criteria criteria = example.createCriteria();
    criteria.andEqualTo("userId",userId);
    criteria.andEqualTo("added",false);
    criteria.andEqualTo("deleted",false);
    return messageUserMapper.selectByExample(example);
  }
}
